<template>
	<view v-if="showselected">
		<view class="tabbar">
			<view class="box">
				<view class="item" v-for="(item,index) in tabBar.list" :key="item.pagePath"
					@click="switchTab(index,item)">
						
						<view class="icon"
							v-if="item.flag == 'icon'">
							<image :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
							<image :src="item.selectedIconPath" class="icon" v-else>
							<view>
								<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
							</view>
						</view>
						
						<view class="icon seven"
							v-else>
							<image :src="item.iconPath" mode=""></image>
						</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectedIndex: uni.getStorageSync('selectedIndex') || 0,  // 是否选中
				showselected: true, // 是否启用tarBer
				tabBar: {
					list: [{
							"flag": 'icon',
							"pagePath": "pages/index/index",
							"iconPath": "/../static/images/1-001.png",
							"selectedIconPath": "/../static/images/1-001.png",
							"text": ""
						},{
							"flag": 'icon',
							"pagePath": "pages/order_addcart/order_addcart",
							"iconPath": "/../static/images/3-001.png",
							"selectedIconPath": "/../static/images/3-001.png",
							"text": ""
						},{
							"flag": 'icon',
							"pagePath": "/pages/user/index",
							"iconPath": "/../static/images/4-001.png",
							"selectedIconPath": "/../static/images/4-001.png",
							"text": ""
						}
					]
				},
			}
		},
		methods: {
			switchTab(index, item) {
				let url = '/' + item.pagePath
				let pagePath = url
				uni.switchTab({url})
				this.tabBar.list.forEach((v, i) => {
					if (item.pagePath === v.pagePath) {
						uni.setStorageSync('selectedIndex', index);
					}
				})
			}
		},
		
	}
</script>

<style lang="scss">
	
	.tabbar {
		display: none;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 74rpx;
		z-index: 999;
		background: #ffffff;
		border-top: 2rpx solid #eee;
		
		.box {
			padding: 0 40rpx;
			display: flex;
			justify-content: space-around;
			.item {
				width: 15%;
				
				.icon {
					margin-top: 10rpx;
					width: 100%;
					font-size: 24rpx;
					color: #8a8a8a;
					
					text-align: center;
					image {
						width: 50rpx;
						height: 50rpx;
					}
					
					.text-active {
						color: #c5cde6;
					}
				}
				.seven {
					height: 100rpx;
					background-color: #dcdaef;
					border-radius: 0rpx 0rpx 35rpx 35rpx;
					line-height: 130rpx;
					
					image {
						width: 70rpx;
						height: 70rpx;
					}
				}
			}
		}
	}
	 
</style>
